package work;

public class Drink {
    private int capacity,price;
    private String name,pack;
    Drink(){
        capacity = 500;
        price = 3;
        pack = "罐装";
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getPack() {
        return pack;
    }

    public void setPack(String pack) {
        this.pack = pack;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void buy(){
        System.out.println("购买饮料");
    }
}

class water extends Drink{
    public void buy(){
        System.out.println("购买矿泉水\n"+this.toString());
    }

    @Override
    public String toString() {
        return "water{"+super.getName()+","+super.getPack()+","+super.getCapacity()+","+super.getPrice()+"}";
    }
}
class coffee extends Drink{
    //多态情况下，可以给成员变成设置成静态成员变量，这样在调用时可以用类名.变量名调用，省去强制类型转换的过程
    private String add;
    public coffee(){}
    public coffee(String add) {
        super.setName("咖啡");
        this.add = add;
    }

    public void buy(){
        System.out.println("购买咖啡\n"+this.toString());
    }

    @Override
    public String toString() {
        return "coffee{"+super.getName()+add+","+super.getPack()+","+super.getCapacity()+","+super.getPrice()+"}";
    }
}
class cola extends Drink{
    private String brand;
    public cola(){}
    public cola(String brand){
        super.setName("可乐");
        this.brand = brand;
    }
    public void buy(){
        System.out.println("购买可乐\n"+this.toString());
    }

    @Override
    public String toString() {
        return "cola{"+brand+super.getName()+","+super.getPack()+","+super.getCapacity()+","+super.getPrice()+"}";
    }
}